package com.pansoft.openplanet.fragment;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.efounder.frame.baseui.BaseFragment;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.adapter.MarketListAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

/**
 * 卖米列表，按钮显示为出售，用户出售数字币给对方
 * Created by will on 18-3-28.
 */

public class MarketSellListFragment extends BaseFragment {

    private static final String TAG = "MarketSellListFragment";

    private RecyclerView recyclerView;
    private MarketListAdapter adapter;

    int requestCount = 0;
    private SmartRefreshLayout refreshLayout;
    private boolean showLoading = true;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.talk_chain_fragment_market_list, null);
        recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        refreshLayout = view.findViewById(R.id.refreshLayout);
        refreshLayout.setEnableAutoLoadMore(false);//开启自动加载功能（非必须）
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
                showLoading = false;
                initData();

            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
                refreshLayout.finishLoadMore();
            }
        });
        initData();
        adapter = new MarketListAdapter(getActivity(), true);
        recyclerView.setAdapter(adapter);
        EditText editText;
        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        RefWatcher refWatcher = TalcChainApplication.getRefWatcher(getActivity());
//        refWatcher.watch(this);
    }

    private void initData() {
        refreshLayout.finishRefresh();
    }

}
